import type { RouteObject } from "react-router-dom";
import { componentMap } from "../router/routerMap";
import type { MenuItem } from "@/api/users";

export const generateRoutes = (menuList: MenuItem[]):RouteObject[] => { 
    return menuList.map((item:MenuItem) => { 
        const hasChildren = item.children
        const routerObj:RouteObject = { 
            path:item.key,
            element:hasChildren?null:<>{componentMap[item.key]}</>,
        }
        if(item.children) { 
            routerObj.children = generateRoutes(item.children)
        }
        return routerObj
    })

}
